Page({
  data: {
    activeFilter: 'all',
    filters: [
      { id: 'all', name: '全部' },
      { id: 'course', name: '课程' },
      { id: 'video', name: '视频' },
      { id: 'article', name: '文章' }
    ],
    historyList: []
  },

  onLoad() {
    this.loadHistory();
  },

  // 切换筛选条件
  changeFilter(e) {
    const filterId = e.currentTarget.dataset.id;
    this.setData({
      activeFilter: filterId
    });
    this.loadHistory(filterId);
  },

  // 加载历史记录
  loadHistory(filter = 'all') {
    wx.showLoading({ title: '加载中...' });
    wx.request({
      url: 'https://your-api.com/api/history',
      data: { filter },
      success: (res) => {
        wx.hideLoading();
        if (res.data.code === 200) {
          this.setData({
            historyList: res.data.data
          });
        }
      },
      fail: () => {
        wx.hideLoading();
        wx.showToast({
          title: '加载失败',
          icon: 'none'
        });
      }
    });
  },

  // 查看历史详情
  viewHistoryDetail(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/history/detail?id=${id}`
    });
  }
});